package wechat

import (
	"context"
	"gitee.com/Cauchy_AQ/vxopen/rpc/wechat/wechat"

	"gitee.com/Cauchy_AQ/vxopen/api/internal/svc"
	"gitee.com/Cauchy_AQ/vxopen/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HeartbeatLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHeartbeatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HeartbeatLogic {
	return &HeartbeatLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HeartbeatLogic) Heartbeat(req *types.HeartbeatReq) (resp *types.HeartbeatResp, err error) {
	rpcResp, err := l.svcCtx.Wechat.Heartbeat(l.ctx, &wechat.HeartbeatReq{
		Ticket: req.Ticket,
	})
	if err != nil {
		return nil, err
	}

	return &types.HeartbeatResp{
		Status:       rpcResp.Status,
		Msg:          rpcResp.Msg,
		AccessToken:  rpcResp.AccessToken,
		RefreshToken: rpcResp.RefreshToken,
	}, nil
}
